<?php

// phpinfo();

require_once 'mp3\Smarty.php';
require_once 'mp3\GestionarPlaylist.php';

$smarty = new mp3_Smarty();
session_start();
require 'mp3/ComprovarSessio.php';
echo $smarty->fetch('mp3\header.tpl');


if (isset($_SESSION['userid'])){
	if (array_key_exists('veure', $_POST)){
		
		$playlists =Mp3_GestionarPlaylist::allPlaylists($_SESSION['userid']);
		$smarty->assign('playlists', $playlists);
		$smarty->assign('on', 'veurePlaylists.php');
		echo $smarty->fetch('mp3\afegirPlaylist.tpl');
		echo $smarty->fetch('mp3\footer.tpl');
	}
	else if (array_key_exists('pl2', $_POST)){
		//Reproduir
		if (isset ($_GET['playlistid']) && $_GET['playlistid']>0){
			$_SESSION['playlistid'] = $_GET['playlistid'];
			$playlist = new Mp3_GestionarPlaylist($_GET['playlistid']);
			$smarty->assign('url', $playlist->xml);
			echo $smarty->fetch('mp3\reproductor.tpl');
			echo $smarty->fetch('mp3\footer.tpl');
		}
	}
}
//	$smarty->assign('arxiu', $_POST['arxiu']);
//	$smarty->assign('canco', $canco);
//	echo $smarty->fetch('mp3\formulari.tpl');
